package com.hbnu.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hbnu.system.config.BaseException;
import com.hbnu.system.constant.RoleConstant;
import com.hbnu.system.constant.StatusCheckConstant;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.service.IBeanService;
import com.hbnu.system.core.util.PageUtil;
import com.hbnu.system.mapper.AwardMapper;
import com.hbnu.system.model.context.BaseContext;
import com.hbnu.system.model.dto.AwardAddDTO;
import com.hbnu.system.model.dto.AwardDTO;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.entity.*;
import com.hbnu.system.model.query.AwardPageQuery;
import com.hbnu.system.model.vo.AwardVO;
import com.hbnu.system.service.*;
import com.hbnu.system.utils.CheckAuditHelper;
import com.hbnu.system.utils.CheckRoleUtil;
import com.hbnu.system.utils.UserInfoUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@Service
public class AwardServiceImpl extends ServiceImpl<AwardMapper, Award> implements IAwardService {

    @Autowired
    private IAwardService iAwardService;
    @Autowired private IUserService iUserService;
    @Autowired private IBeanService iBeanService;

    @Autowired private IDeptService iDeptService;
    @Autowired IAuthorityService iAuthorityService;
    @Autowired AuditService auditService;
    
    @Autowired private IAwardauthorService awardauthorService;
    
    @Autowired private AwardfileService awardfileService;
    
    @Autowired private IAwardQualificationService awardQualificationService;
    
    @Autowired private IdToStatsService idToStatsService;

    @Autowired private IAwardprojectService awardprojectService;

    @Autowired private AwardMapper awardMapper;
    @Autowired
    private CheckRoleUtil checkRoleUtil;
    @Autowired
    private CheckAuditHelper checkAuditHelper ;

    @Autowired
    private UserInfoUtils userInfoUtils;

    @Override
    public boolean addAward(Award award) {

        checkAddAward(award);

        award.setEnteredDate(LocalDateTime.now());
        award.setStatus("草稿");
        if (StrUtil.isEmpty(award.getLeadAuthor()) || StrUtil.isBlank(award.getLeadAuthor())){
            award.setLeadAuthor("");
        }
        if (StrUtil.isEmpty(award.getCorrespondingAuthor()) || StrUtil.isBlank(award.getCorrespondingAuthor())){
            award.setCorrespondingAuthor("");
        }

        return baseMapper.insert(award) == 1;
    }



    @Override
    public boolean addAward(AwardAddDTO awardAddDTO) {
        checkAddAwardAddDTO(awardAddDTO);
        Award award = new Award();
        award.setOrganization(awardAddDTO.getOrganization());
        award.setSignedUnit(awardAddDTO.getSignedunit());
        award.setAwardName(awardAddDTO.getAwardname());
        award.setAwardResult(awardAddDTO.getAwardresult());
        award.setAwardCate(awardAddDTO.getAwardcate());
        award.setEntered(awardAddDTO.getEntered());

        award.setClassifi("");
        award.setAwardLevel("");
        award.setAwardGrant("");
        award.setStatus("草稿");
        award.setEnteredDate(LocalDateTime.now());
//        award.setDept(iUserService.getOne(Wrappers.lambdaQuery(User.class).eq(User::getName,award.getEntered())).getDept());
        String dept = iUserService.getOne(Wrappers.lambdaQuery(User.class).eq(User::getName, award.getEntered())).getDept();
        String deptName = iDeptService.getById(dept).getDeptName();
        award.setDept(deptName);
        return baseMapper.insert(award) == 1;
    }


    /**
     * 删除成果
     * @param awardId  成果id
     * @return
     * @throws IOException
     */
    @Override
    public boolean deleteaward(String awardId) throws IOException {
        // 校验普通用户权限不能修改当前状态信息
        Award award = super.getOne(Wrappers.lambdaQuery(Award.class)
                .eq(Award::getAwardID, awardId));
        checkRoleUtil.checkPermissionAchievement(award.getStatus());

        // 删除成果关联的作者根据成果id
        awardauthorService.remove(Wrappers.lambdaQuery(Awardauthor.class)
                .eq(Awardauthor::getAwardID, awardId));

        // 删除成果关联的文件信息根据成果id
        awardfileService.remove(Wrappers.lambdaQuery(Awardfile.class)
                .eq(Awardfile::getAwardid, awardId));

        // 删除成果关联的量化分数根据成果id
        awardQualificationService.remove(Wrappers.lambdaQuery(Award_Qualification.class)
                .eq(Award_Qualification::getAwardID, awardId));

        // 删除文件信息
        List<Awardfile> awardFiles = awardfileService.list(Wrappers.lambdaQuery(Awardfile.class)
                .eq(Awardfile::getAwardid, awardId));
        List<String> fileIds = awardFiles.stream()
                .map(Awardfile::getFileid)
                .collect(Collectors.toList());
        for (String fileId : fileIds) {
            awardfileService.deleteAwardfile(fileId);
        }
        // 删除审核记录根据成果ID
        auditService.remove(Wrappers.lambdaQuery(Audit.class)
                .eq(Audit::getSynthesisID, awardId));

        // 最后删除成果本身
        return baseMapper.deleteById(awardId) == 1;
    }


    @Override
    public boolean updateAward(Award award) {
        checkRoleUtil.checkPermissionAchievement(award.getStatus());
        checkupdateAward(award);
        return baseMapper.updateById(award)==1;
    }


    @Override
    public Award getAward(String awardID) {
        Award award= super.getOne(Wrappers.lambdaQuery(Award.class)
                .eq(Award::getAwardID, awardID));
        if(Objects.isNull(award)){
            throw new BaseException("成果获奖编号异常!未查找到该获奖");
        }
        return award;
    }

    @Override
    public AwardDTO getAwardDTOById(String awardID) {
        Award award= super.getOne(Wrappers.lambdaQuery(Award.class)
                .eq(Award::getAwardID, awardID));
        if(Objects.isNull(award)){
            throw new BaseException("成果获奖编号异常!未查找到该获奖");
        }

        String entered = idToStatsService.IdToName(award.getEntered());
        String dept=idToStatsService.IdToDept(award.getDept());
        String allauthor=idToStatsService.IdToAllauthor(award.getAllAuthor());

        AwardDTO awarddto = new AwardDTO();
        BeanUtils.copyProperties(award,awarddto);

        awarddto.setAllAuthorName(allauthor);
        awarddto.setEnteredName(entered);
        awarddto.setDeptName(dept);
        return awarddto;
    }



    @Override
    public boolean checkAwardName(String awardname) {
        Award one = super.getOne(Wrappers.lambdaQuery(Award.class)
                .eq(Award::getAwardName, awardname));
        if(Objects.nonNull(one)){
            throw new BaseException("该成果名称已存在!");
        }
        return true;
    }

    @Override
    public IPage<Award> pageCondition(SearchPageDTO searchPageDTO) {

        IPage<Award> award = PageUtil.getPage(searchPageDTO.getPageNum(), searchPageDTO.getPageSize());
        LambdaQueryWrapper<Award> wrapper = Wrappers.lambdaQuery(Award.class);
        IPage<Award> awardIPage = baseMapper.selectPage(award, wrapper);
//        IPage<PaperVO> taskVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        List<Award> records = awardIPage.getRecords();
        List<Award> PaperS = new ArrayList<>();

        int count = 1;
        int start = searchPageDTO.getPageSize() * (searchPageDTO.getPageNum()-1)+1;
        int end = searchPageDTO.getPageNum() * searchPageDTO.getPageSize();
//        records.forEach(record->{
//            if (count >= start && count <= end){
//                PaperS.add(this.getPaper(record.getPaperID()));
//            }
//        });
        Collections.reverse(records);
        for (Award record:records) {
            if (count >= start && count <= end){
                PaperS.add(record);
            }
            count += 1;
        }


//        Collections.reverse(PaperS);
        awardIPage.setRecords(PaperS);
        awardIPage.setTotal(PaperS.size());
        return awardIPage;
    }

    @Override
    public AwardVO getAwardVO(String id) {
        List<Award> tasks = baseMapper.selectList(Wrappers.lambdaQuery(Award.class)
                .eq(Award::getAwardID, id));
        Award task = tasks.get(0);

        List<AwardVO> taskVOS = iBeanService.copyListProperties(tasks,AwardVO.class);
        AwardVO awardVO = taskVOS.get(0);
        awardVO.setAwardID(task.getAwardID());
//        awardVO.setAwardname(task.getAwardName());
//        awardVO.setAwardresult(task.getAwardResult());
        awardVO.setOrganization(task.getOrganization());
//        awardVO.setAwardgrant(task.getAwardGrant());
//        awardVO.setAwardlevel(task.getAwardLevel());
//        awardVO.setAwarddate(task.getAwardDate());
//        awardVO.setAwardcate(task.getAwardCate());
//        awardVO.setIssueunit(task.getIssueUnit());
//        awardVO.setAllauthor(task.getAllAuthor());
        awardVO.setStatus(task.getStatus());
        return awardVO;
    }

    /**
     * 学院成果审核通过
     * @param token
     * @param awardId
     * @return
     */
    @Override
    public Boolean collegeCheckPass(String token, String awardId) {
        Award award = iAwardService.getAward(awardId);
        if (award == null) throw new BaseException("该成果编号有误!");

        String roleName = userInfoUtils.getCurrentUserInfo().getRoleName();

        // 目标状态
        String targetStatus = StatusCheckConstant.COLLEGE_CHECK_PEOPLE.equals(roleName)
                ? StatusCheckConstant.WAIT_SCHOOL_CHECK
                : StatusCheckConstant.CHECK_PASS;


        return checkAuditHelper.doPassAudit(
                award,
                StatusCheckConstant.WAIT_COLLEGE_CHECK,
                targetStatus,
                roleName,
                "成果",
                award::getAwardID,
                award::getStatus,
                award::setStatus,
                this::updateAwardByEntity
        );
    }

    /**
     * 学院成果审核退回
     * @param token
     * @param checkBackDTO
     * @return
     */
    @Override
    public Boolean collegeCheckBack(String token, CheckBackDTO checkBackDTO) {
        Award award = iAwardService.getAward(checkBackDTO.getID());
        if (award == null) throw new BaseException("该成果编号有误!");

        String roleName = userInfoUtils.getCurrentUserInfo().getRoleName();
        String backStatus = StatusCheckConstant.COLLEGE_CHECK_PEOPLE.equals(roleName)
                ? StatusCheckConstant.COLLEGE_CHECK_BACK
                : StatusCheckConstant.SCHOOL_CHECK_BACK;

        return checkAuditHelper.doBackAudit(
                award,
                StatusCheckConstant.WAIT_COLLEGE_CHECK,
                backStatus,
                checkBackDTO.getReason(),
                "成果",
                award::getAwardID,
                award::getStatus,
                award::setStatus,
                award::setReason,
                this::updateAwardByEntity
        );
    }

    /**
     * 学校成果审核通过
     * @param token
     * @param awardId
     * @return
     */
    @Override
    public Boolean schoolCheckPass(String token, String awardId) {
        Award award = iAwardService.getAward(awardId);
        if (award == null) throw new BaseException("该成果编号有误!");

        String currentStatus = award.getStatus();
        if (!StatusCheckConstant.WAIT_SCHOOL_CHECK.equals(currentStatus)
                && !StatusCheckConstant.WAIT_COLLEGE_CHECK.equals(currentStatus)) {
            throw new BaseException("该成果状态不处于该环节!");
        }


        String roleName = userInfoUtils.getCurrentUserInfo().getRoleName();

        return checkAuditHelper.doPassAudit(
                award,
                currentStatus,
                StatusCheckConstant.CHECK_PASS,
                roleName,
                "成果",
                award::getAwardID,
                award::getStatus,
                award::setStatus,
                this::updateAwardByEntity
        );
    }

    /**
     * 学校成果审核退回
     * @param token
     * @param checkBackDTO
     * @return
     */
    @Override
    public Boolean schoolCheckBack(String token, CheckBackDTO checkBackDTO) {
        Award award = iAwardService.getAward(checkBackDTO.getID());
        if (award == null) throw new BaseException("该成果编号有误!");

        String currentStatus = award.getStatus();
        if (!StatusCheckConstant.WAIT_SCHOOL_CHECK.equals(currentStatus)
                && !StatusCheckConstant.WAIT_COLLEGE_CHECK.equals(currentStatus)
                && !StatusCheckConstant.CHECK_PASS.equals(currentStatus)) {
            throw new BaseException("该成果状态不处于该环节!");
        }

        String roleName = userInfoUtils.getCurrentUserInfo().getRoleName();

        return checkAuditHelper.doBackAudit(
                award,
                currentStatus,
                StatusCheckConstant.SCHOOL_CHECK_BACK,
                checkBackDTO.getReason(),
                "成果",
                award::getAwardID,
                award::getStatus,
                award::setStatus,
                award::setReason,
                this::updateAwardByEntity
        );
    }

    /**
     * 更新成果实体方法
     */
    private Boolean updateAwardByEntity(Award award) {
        return baseMapper.updateById(award) == 1;
    }


    @Override
    public Boolean withdrawAward(String id) {
        // 获取当前用户ID
        String userId = BaseContext.getCurrentId();
        // 验证用户是否存在
        User user = iUserService.getById(userId);
        if (Objects.isNull(user)) {
            throw new BaseException("用户不存在");
        }
        
        // 查询奖励信息
        Award award = super.getOne(Wrappers.lambdaQuery(Award.class).eq(Award::getAwardID, id));
        if (Objects.isNull(award)) {
            throw new BaseException("奖励不存在");
        }
        
        // 检查奖励状态是否为院级审核中
        if (!award.getStatus().equals(StatusCheckConstant.WAIT_COLLEGE_CHECK)) {
            throw new BaseException("只有院级审核中的奖励才能撤回");
        }
        
        // 将奖励状态更新为草稿
        award.setStatus(StatusCheckConstant.DRAFT);
        
        return baseMapper.updateById(award) == 1;
    }
    
    @Override
    public Boolean ReCommitAward(String id) {
        Award award = super.getOne(Wrappers.lambdaQuery(Award.class)
                .eq(Award::getAwardID,id));
        checkCommitField(award);
        award.setStatus("待院级审核");
        award.setReason("");
        return baseMapper.updateById(award)==1;
    }


    /**
     * 成果分页查询
     * @param awardPageQuery
     * @return
     */
    @Override
    public CommonPage<AwardVO> userGetRelateAward(AwardPageQuery awardPageQuery) {

        String userId = BaseContext.getCurrentId();
        User user = iUserService.getById(userId);
        String role = user.getRole();

        // 创建MyBatis-Plus的Page对象
        Page<AwardVO> page = new Page<>(awardPageQuery.getPageNum(), awardPageQuery.getPageSize());
        IPage<AwardVO> awardIPage = null;
        // 根据角色执行不同查询
        if (role.equals(RoleConstant.ROLE_ADMIN_SCHOOL)) {
            awardIPage = awardMapper.schoolGetRelateAwardQuery(page, awardPageQuery, user);
        } else if (role.equals(RoleConstant.ROLE_ADMIN_COLLEGE)) {
            awardIPage = awardMapper.collegeGetRelateAwardQuery(page, awardPageQuery, user);
        } else {
            awardIPage = awardMapper.userGetRelateAwardQuery(page, awardPageQuery, user);
        }
        // 初始化量化分数
        float figure = 0;

        //查询专利关联的作者
        // 遍历记录，计算量化分数
        List<AwardVO> records = awardIPage.getRecords();
        for (AwardVO record : records) {
            if (record.getStatus().equals("审核通过")){
                figure += record.getScore();
            }
        }

        // 构造返回分页对象
        CommonPage<AwardVO> awardCommonPage = CommonPage.restPage(awardIPage);

        awardCommonPage.setFigure(figure);
        awardCommonPage.setList(records);

        return awardCommonPage;


    }

    @Override
    public CommonPage<Award> export(AwardPageQuery awardPageQuery) {
        String userId = BaseContext.getCurrentId();
        User user = iUserService.getById(userId);
        String role = user.getRole();

        Page<Award> page = new Page<>(awardPageQuery.getPageNum(), awardPageQuery.getPageSize());
        IPage<Award> awardIPage;

        if (RoleConstant.ROLE_ADMIN_SCHOOL.equals(role)) {
            awardIPage = awardMapper.schoolExportRelateAwardQuery(page, awardPageQuery, user);
        } else if (RoleConstant.ROLE_ADMIN_COLLEGE.equals(role)) {
            awardIPage = awardMapper.collegeExportRelateAwardQuery(page, awardPageQuery, user);
        } else {
            awardIPage = awardMapper.userExportRelateAwardQuery(page, awardPageQuery, user);
        }

        List<Award> records = awardIPage.getRecords();

        float figure = 0;
        for (Award record : records) {
            if (StatusCheckConstant.CHECK_PASS.equals(record.getStatus())) {
                figure += record.getScore();
            }

            // 查询第一作者/共同第一作者
            List<Awardauthor> leadAuthors = awardauthorService.list(Wrappers.lambdaQuery(Awardauthor.class)
                    .eq(Awardauthor::getAwardID, record.getAwardID())
                    .in(Awardauthor::getAuthortype, Arrays.asList("第一作者", "共同第一作者")));
            record.setLeadAuthor(leadAuthors.stream().map(Awardauthor::getName).collect(Collectors.joining(",")));

            // 查询通讯作者
            List<Awardauthor> contactAuthors = awardauthorService.list(Wrappers.lambdaQuery(Awardauthor.class)
                    .eq(Awardauthor::getAwardID, record.getAwardID())
                    .eq(Awardauthor::getAuthortype, "通讯作者"));
            record.setCorrespondingAuthor(contactAuthors.stream().map(Awardauthor::getName).collect(Collectors.joining(",")));

            // 查询关联项目
            List<Awardproject> awardProjects = awardprojectService.list(Wrappers.lambdaQuery(Awardproject.class)
                    .eq(Awardproject::getAwardID, record.getAwardID()));
            record.setAssociatedProjects(awardProjects.stream().map(Awardproject::getProjectname).collect(Collectors.joining(",")));

            // 转化allAuthors
            String allAuthor = idToStatsService.IdToAllauthor(record.getAllAuthor());
            record.setAllAuthor(allAuthor);

            // 替换entered值为用户姓名
            String entered = idToStatsService.IdToEntered(record.getEntered());
            record.setEntered(entered);

            // 替换dept值为部门名称
            String deptName = idToStatsService.IdToDept(record.getDept());
            record.setDept(deptName);
        }

        CommonPage<Award> awardCommonPage = CommonPage.restPage(awardIPage);
        awardCommonPage.setFigure(figure);
        awardCommonPage.setList(records);
        return awardCommonPage;
    }


    /**
     * 添加成果进行参数校验
     * @param award
     */
    private void checkAddAward(Award award) {
        if(StrUtil.isEmpty(award.getEntered()) || StrUtil.isBlank(award.getEntered())){
            throw new BaseException("请输入录入人");
        }
        if(Objects.nonNull(super.getOne(Wrappers.lambdaQuery(Award.class)
                .eq(Award::getAwardName,award.getAwardName())))){
            throw new BaseException("名称重复!");
        }
        if(StrUtil.isEmpty(award.getAwardResult()) || StrUtil.isBlank(award.getAwardResult())){
            throw new BaseException("请输入获奖成果");
        }
        if(StrUtil.isEmpty(award.getAwardCate()) || StrUtil.isBlank(award.getAwardCate())){
            throw new BaseException("请输入奖励类别");
        }
    }


    /**
     * 添加成果AddDTO进行参数校验
     * @param awardAddDTO
     */
    private void checkAddAwardAddDTO(AwardAddDTO awardAddDTO) {
        if(StrUtil.isEmpty(awardAddDTO.getEntered()) || StrUtil.isBlank(awardAddDTO.getEntered())){
            throw new BaseException("请输入录入人");
        }
        if(StrUtil.isEmpty(awardAddDTO.getSignedunit()) || StrUtil.isBlank(awardAddDTO.getSignedunit())){
            throw new BaseException("请输入署名单位");
        }
        checkAwardName(awardAddDTO.getAwardname());
        if(StrUtil.isEmpty(awardAddDTO.getAwardresult()) || StrUtil.isBlank(awardAddDTO.getAwardresult())){
            throw new BaseException("请输入获奖成果");
        }
        if(StrUtil.isEmpty(awardAddDTO.getAwardcate()) || StrUtil.isBlank(awardAddDTO.getAwardcate())){
            throw new BaseException("请输入奖励类别");
        }
    }

    /**
     * 更新成果award进行参数校验
     * @param award
     */
    private void checkupdateAward(Award award) {
        if(StrUtil.isEmpty(award.getEntered()) || StrUtil.isBlank(award.getEntered())){
            throw new BaseException("请输入录入人");
        }
        if(StrUtil.isEmpty(award.getSignedUnit()) || StrUtil.isBlank(award.getSignedUnit())){
            throw new BaseException("请输入署名单位");
        }
        if(StrUtil.isEmpty(award.getAwardResult()) || StrUtil.isBlank(award.getAwardResult())){
            throw new BaseException("请输入获奖成果");
        }
        if(StrUtil.isEmpty(award.getAwardCate()) || StrUtil.isBlank(award.getAwardCate())){
            throw new BaseException("请输入奖励类别");
        }
    }


    /**
     * 检查提交字段是否填写
     * @param award
     */
    private void checkCommitField(Award award) {
        if(Objects.isNull(award)){
            throw new BaseException("成果编号有误!");
        }
        //检查各项不可为空选项
        if (StrUtil.isEmpty(award.getClassifi()) || StrUtil.isBlank(award.getClassifi())){
            throw new BaseException("请输入统计分类!");
        }
//        if (StrUtil.isEmpty(award.getOrganization()) || StrUtil.isBlank(award.getOrganization())){
//            throw new BaseException("请输入所属机构!");
//        }
        if (StrUtil.isEmpty(award.getSignedUnit()) || StrUtil.isBlank(award.getSignedUnit())){
            throw new BaseException("请输入署名单位!");
        }
        if (StrUtil.isEmpty(award.getAwardName()) || StrUtil.isBlank(award.getAwardName())){
            throw new BaseException("请输入奖励名称!");
        }
        if (StrUtil.isEmpty(award.getAwardResult()) || StrUtil.isBlank(award.getAwardResult())){
            throw new BaseException("请输入获奖成果!");
        }
        //!!!!!!!!!!!!还没对第一作者的身份进行核实
        if (StrUtil.isEmpty(award.getAwardLevel()) || StrUtil.isBlank(award.getAwardLevel())){
            throw new BaseException("请输入获奖级别!");
        }

        if (StrUtil.isEmpty(award.getAwardCate()) || StrUtil.isBlank(award.getAwardCate())){
            throw new BaseException("请输入获奖类别!");
        }
        if (StrUtil.isEmpty(award.getAwardGrant()) || StrUtil.isBlank(award.getAwardGrant())){
            throw new BaseException("请输入获奖批准号");
        }
        if (StrUtil.isEmpty(award.getAwardUnit()) || StrUtil.isBlank(award.getAwardUnit())){
            throw new BaseException("请输入奖励申报单位!");
        }
        if (StrUtil.isEmpty(award.getDiscipline()) || StrUtil.isBlank(award.getDiscipline())){
            throw new BaseException("请输入学科门类!");
        }
        if (StrUtil.isEmpty(award.getIssueUnit()) || StrUtil.isBlank(award.getIssueUnit())){
            throw new BaseException("请输入颁发奖励单位!");
        }
        if (StrUtil.isEmpty(award.getEntered()) || StrUtil.isBlank(award.getEntered())){
            throw new BaseException("请输入录入人!");
        }
        
        // 检查量化分数是否填写
        Award_Qualification qualification = awardQualificationService.getOne(
                Wrappers.lambdaQuery(Award_Qualification.class)
                        .eq(Award_Qualification::getAwardID, award.getAwardID())
        );
        if (Objects.isNull(qualification)) {
            throw new BaseException("请先填写奖励的量化分数!");
        }
        
        // 检查作者列表是否填写
        List<Awardauthor> authorList = awardauthorService.list(
                Wrappers.lambdaQuery(Awardauthor.class)
                        .eq(Awardauthor::getAwardID, award.getAwardID())
        );
        if (CollectionUtils.isEmpty(authorList)) {
            throw new BaseException("请先添加奖励的作者信息!");
        }
    }


}
